<?php
/**
 * CreateTime: 2023/6/12 16:24
 */

namespace App\Func;

use App\Models\Auth\RoleModel;
use App\Models\Staff\cStaffRole;
use App\Models\Staff\StaffRoleModel;
use App\Scopes\MediationStaffScope;

class RoleFunc
{
    /**
     * 通过角色code获取拥有当前角色的用户
     * @param $roleCode
     * @return array
     */
    public function getStaffIdsByRoleCode($roleCode): array
    {
        // 获取权限id
        $roleModel = new RoleModel();
        $role_id = isset($roleModel->getRoleIdsByRoleCode($roleCode)['role_id']) ? $roleModel->getRoleIdsByRoleCode($roleCode)['role_id'] : 0;
        // 如果当前角色code 隐射不到role_id 则直接返回空数组
        if(!$role_id){
            return [];
        }
        $staffRoleModel = new StaffRoleModel();
        $staffIds = $staffRoleModel->select(['staff_id'])
            ->where('role_id',$role_id)
            ->withoutGlobalScopes()
            ->get()
            ->toArray();
        return array_column($staffIds,'staff_id');
    }
}